Skip to content

fix(assistant): accept plain functions as listener middleware - #1591

Open
sahiljagtap08 wants to merge 1 commit into
slackapi:mainfrom
sahiljagtap08:fix/assistant-function-middleware
Open

sahiljagtap08 wants to merge 1 commit into
slackapi:mainfrom
sahiljagtap08:fix/assistant-function-middleware

Conversation

@sahiljagtap08

@sahiljagtap08 sahiljagtap08 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Assistant and AsyncAssistant listener decorators (thread_started, user_message, and so on) are typed to accept middleware as a list of plain functions or Middleware objects, the same as App.event(). But build_listener passed the list straight to CustomListener without wrapping functions, so a plain function middleware raised:

AttributeError: 'function' object has no attribute 'process'

on every matching event, which became a 500.

A second problem in the same code: build_listener inserted AttachingConversationKwargs into the caller's list in place. A list shared between two decorators ended up with that middleware added twice.

Changes in slack_bolt/middleware/assistant/:

  • Plain functions are wrapped in CustomMiddleware (sync) or AsyncCustomMiddleware (async), matching what App._register_listener does. Anything else raises the same BoltError that App raises.
  • A new middleware list is built for each listener, so the caller's list is left untouched.
  • The build_listener type hint now matches the decorator type hints.

Testing

Added test_assistant_with_function_listener_middleware to both tests/scenario_tests/test_events_assistant.py and tests/scenario_tests_async/test_events_assistant.py. Each registers a function middleware on two listeners, checks the middleware and listener both run, and checks the caller's list is unchanged. Both fail on main and pass with this change. Ran ./scripts/format.sh, ./scripts/lint.sh, ./scripts/run_mypy.sh, and the assistant test files.

Category

  • slack_bolt.App and/or its core components
  • slack_bolt.async_app.AsyncApp and/or its core components
  • Adapters in slack_bolt.adapter
  • Others

Requirements

  • I've read and understood the Contributing Guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've run ./scripts/install_all_and_run_tests.sh after making the changes.

Fixes #1597

Assistant listener decorators advertise middleware as a list of
functions or Middleware objects, like App does. build_listener passed
the list straight to CustomListener, so a plain function raised
AttributeError ('function' object has no attribute 'process') on every
matching event. It also inserted AttachingConversationKwargs into the
caller's list, so a list shared between decorators grew on each use.

- Wrap plain functions in CustomMiddleware / AsyncCustomMiddleware
- Build a new middleware list instead of editing the caller's
- Add sync and async tests using a function middleware

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Assistant listener middleware crashes when given a plain function

1 participant